package main

import "fmt"

func main() {
	var arr1 [6]int
	var slice1 []int = arr1[2:5]
	for i := 0; i < len(arr1); i++ {
		arr1[i] = i
	}
	for i := 0; i < len(slice1); i++ {
		fmt.Println(slice1[i])
	}
	fmt.Printf("The length of arr1 is %d\n", len(arr1))
	fmt.Printf("The length of slice1 is %d\n", len(slice1))
	fmt.Printf("The capacity of slice1 is %d\n", cap(slice1))
	//切片在切片
	slice1 = slice1[0:4]
	fmt.Printf("The length of slice1 is %d\n", len(slice1))
	fmt.Printf("The capacity of slice1 is %d\n", cap(slice1))
	for i := 0; i < len(slice1); i++ {
		fmt.Println(slice1[i])
	}
	b := []byte{'H', 'e', 'l', 'l', 'o'}
	fmt.Printf("%s\n", b[1:4]) // e l l
	fmt.Printf("%s\n", b[:2])  // h e
	fmt.Printf("%s\n", b[2:])  // l l o
	fmt.Printf("%s\n", b[:])   // H e l l o
	var arr = [5]int{0, 1, 2, 3, 4}
	sum(arr[:])
	fmt.Println(sum(arr[:]))
	//make声明切片
	var slice = make([]int, 5, 10)
	fmt.Println(slice)
}

// 将切片传递给函数
func sum(a []int) int {
	s := 0
	for _, v := range a {
		s += a[v]
	}
	return s
}
